package com.souku.finance.application.ui.mine;

import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.TextView;
import android.widget.Toast;

import com.souku.finance.application.R;
import com.souku.finance.application.base.BaseTitleBarActivity;
import com.souku.finance.application.utils.Constant;
import com.souku.finance.application.utils.ShareUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EAccountYetBindingActivity extends BaseTitleBarActivity {

    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_bank_account)
    TextView tvBankAccount;
    @BindView(R.id.tv_copy_account)
    TextView tvCopyAccount;

    String eAccountNum = "";
    String realName = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_eaccount_yet_binding);
        ButterKnife.bind(this);

        eAccountNum = ShareUtil.getInstance().getString(Constant.eAccountNum);
        realName = ShareUtil.getInstance().getString(Constant.realName);

        String realN = " ";

        if (!TextUtils.isEmpty(realName)) {
            realN = realName.substring(0, 1);
            tvName.setText("户名：" + realN + "**");
        } else {
            tvName.setText("户名：" + realN);
        }

        if (TextUtils.isEmpty(eAccountNum)) {
            eAccountNum = "";
            tvBankAccount.setText("账号：" + eAccountNum);
        } else {
            StringBuffer stringBuffer = new StringBuffer();
            for (int i = 0; i < eAccountNum.length(); i++) {
                if (i == 4) {
                    stringBuffer.append(" ");
                } else if (i == 8) {
                    stringBuffer.append(" ");
                } else if (i == 12) {
                    stringBuffer.append(" ");
                } else if (i == 16) {
                    stringBuffer.append(" ");
                } else if (i == 20) {
                    stringBuffer.append(" ");
                } else if (i == 24) {
                    stringBuffer.append(" ");
                }
                stringBuffer.append(eAccountNum.charAt(i));
            }
            tvBankAccount.setText("账号：" + stringBuffer.toString());
        }

    }

    @Override
    public void internet() {

    }

    public void onClickCopy(String eAccountNum) {
        // 从API11开始android推荐使用android.content.ClipboardManager
        // 为了兼容低版本我们这里使用旧版的android.text.ClipboardManager，虽然提示deprecated，但不影响使用。
        ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
        // 将文本内容放到系统剪贴板里。
        cm.setText(eAccountNum);
        Toast.makeText(this, "复制成功", Toast.LENGTH_LONG).show();
    }

    @OnClick(R.id.tv_copy_account)
    public void onViewClicked() {
        onClickCopy(eAccountNum);
    }
}
